﻿@model UI.ServiceReference1.traintype_tbModel

@{
    ViewBag.Title = "traintype";
    Layout = "~/Views/Shared/ShouYe.cshtml";
}
<script src="~/BootstrapSouce/js/jquery.min.js"></script>
<link href="~/BootstrapSouce/css/bootstrap.min.css" rel="stylesheet" />
<script src="~/BootstrapSouce/js/bootstrap.min.js"></script>
<a href="#" class="btn" data-toggle="modal" data-target="#add" style="float:right">添加类型</a>
<table id="t" class="table table-bordered table-hover definewidth m10">
    <thead>
        <tr>
            <th>培训类型编号</th>
            <th>培训类型名称</th>
        </tr>
    </thead>
    <tbody>

    </tbody>
</table>
<div class="modal fade" id="add" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="height:500px;width:500px;left:100px">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    <span class="glyphicon glyphicon-remove"></span>
                </button>
                <h4 class="modal-title" id="myModalLabel">添加培训类型</h4>
            </div>
            <div class=" modal-body">
                <table class="table">
                    <tr>
                        <td>培训类型名称:</td>
                        <td><input id="traintype_name" class="form-control" type="text"></td>
                    </tr>
                </table>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default"
                        data-dismiss="modal">
                    关闭
                </button>
                <button type="button" onclick="funadd()" class="btn btn-primary">
                    发布
                </button>
            </div>
        </div>
    </div>
</div>
@* ------------------------------------------------------分割线 一下是修改的模态框----------------------------------------------------------------------- *@
<div class="modal fade" id="upt" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="height:500px;width:500px;left:100px">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    <span class="glyphicon glyphicon-remove"></span>
                </button>
                <h4 class="modal-title" id="myModalLabel">修改人员培训</h4>
            </div>
            <div class=" modal-body">
                <table class="table">
                    <tr>
                        <td>培训类型名称:</td>
                        <td><input id="traintype_name1" class="form-control" type="text">
                            <input id="traintype_id1" type="hidden" /></td>
                    </tr>
                </table>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default"
                        data-dismiss="modal">
                    关闭
                </button>
                <button type="button" onclick="funupt()" class="btn btn-primary">
                    修改
                </button>
            </div>
        </div>
    </div>
</div>
<script>
   
    show();
    
    function funadd() {
      
        var traintype_name = $("#traintype_name").val();
        $.ajax({
            url: "/Peixun/traintypeadd",
            data: { traintype_name: traintype_name },
            type: "post",
            success: function (obj) {
                if (obj > 0) {
                    alert('添加成功');
                    location.href = '/Peixun/traintype';
                }
                else {
                    alert('添加失败');
                }
            }
        })
    }
    function show() {
        $.ajax({
            url: "/Peixun/traintypeshow1",
            type: "get",
            success: function (obj) {
                obj = JSON.parse(obj);
                // obj = eval(""+obj+"");

                $("#t tbody").empty();
                var str = "";
                for (var i = 0; i < obj.length; i++) {
                    str += "<tr><td>" + obj[i].traintype_name + "</td>";
                    str += "<td><a href='/Peixun/traintypedel?id=" + obj[i].traintype_id + "'>删除</a><input type='button' value='修改'onclick='upt(" + obj[i].traintype_id + ")'data-toggle='modal' data-target='#upt'class='btn btn-primarys' /></td></tr>";
                }
                $("#t tbody").append(str);
                showpage(obj.count);
            }
        })
    }
    function upt(id) {
        
        $.ajax({
            url: "/Peixun/traintypeft?id=" + id,
            type: "get",
            dateType: "json",
            success: function (obj) {
                obj = JSON.parse(obj);
               
                $("#traintype_id1").val(obj.traintype_id);
                    $("#traintype_name1").val(obj.traintype_name);  
            }
        })
    }
    function funupt() {
        var traintype_name = $("#traintype_name1").val();
        var traintype_id = $("#traintype_id1").val();
        $.ajax({
            url: "/Peixun/traintypeupt",
            data: { traintype_id: traintype_id, traintype_name: traintype_name },
            type: "post",
            success: function (obj) {
                if (obj > 0) {
                    alert('修改成功');
                    location.href = '/Peixun/traintype';
                }
                else {
                    alert('修改失败');
                }
            }
        })
    }
</script>

